package tp.pr4;

import java.io.IOException;


import tp.pr4.cityLoader.cityLoaderExceptions.*;

public enum Direction {
	EAST, NORTH, SOUTH, WEST, UNKNOWN;

	/**
	 * Obtiene la direccion opuesta ( punto cardinal )
	 * 
	 * @return la direccion (enum) opuesta
	 */
	public Direction opposite() {
		switch (this) {
		case EAST:
			return WEST;
		case NORTH:
			return SOUTH;
		case SOUTH:
			return NORTH;
		case WEST:
			return EAST;
		default:
			return UNKNOWN;
		}
	}

	/**
	 * Obtiene una nueva direccion aplicando el parametro rotation (realiza el
	 * giro a derecha o izquierda)
	 * 
	 * @return la nueva direccion
	 */
	public Direction rotateLeft() {
		switch (this) {
		case EAST:
			return NORTH;
		case NORTH:
			return WEST;
		case SOUTH:
			return EAST;
		case WEST:
			return SOUTH;
		default:
			return UNKNOWN;
		}
	}

	public Direction rotateRight() {
		switch (this) {
		case EAST:
			return SOUTH;
		case NORTH:
			return EAST;
		case SOUTH:
			return WEST;
		case WEST:
			return NORTH;
		default:
			return UNKNOWN;
		}
	}
	
	public static Direction parseDirection(String s) throws WrongCityFormatException{
		Direction ret;
		if (s.equalsIgnoreCase("EAST")) ret = EAST;
		else if (s.equalsIgnoreCase("NORTH")) ret = Direction.NORTH;
		else if (s.equalsIgnoreCase("SOUTH")) ret = Direction.SOUTH;
		else if (s.equalsIgnoreCase("WEST")) ret = Direction.WEST;
		else throw new WrongCityFormatException();
		return ret;
			
	}
}
